﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="SubContracts.aspx.cs" Inherits="PmSadis.WebFormsUi.Operator.SubContracts" %>

<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.2, Version=11.2.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxGridLookup" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.2, Version=11.2.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.2, Version=11.2.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.2, Version=11.2.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web" TagPrefix="dx" %>
<%--<asp:Content ID="subContractsHead" ContentPlaceHolderID="head" runat="server">
</asp:Content>--%>
<asp:Content ID="subContractsContent" ContentPlaceHolderID="content" runat="server">
    <link href="../Content/oper.subcontracts.css" rel="stylesheet" type="text/css" />
    <h2>
        Субконтракты</h2>
    <asp:ScriptManager ID="subContractsScriptManager" runat="server" />
    <!--sub contracts data source-->
    <asp:ObjectDataSource ID="dsSubContracts" runat="server" TypeName="PmSadis.WebFormsUi.Operator.SubContracts"
        SelectMethod="GetAll" InsertMethod="InsertSubContract" UpdateMethod="UpdateSubContract"
        DeleteMethod="DeleteSubContract" />
    <!--sub contract objects data source-->
    <asp:ObjectDataSource ID="dsObjects" runat="server" TypeName="PmSadis.WebFormsUi.Operator.SubContracts"
        SelectMethod="SubContractObjects" DeleteMethod="UnlinkObject" UpdateMethod="UpdateObjectInContract">
        <SelectParameters>
            <asp:SessionParameter Name="subContractId" SessionField="oper-expanded-subcontract-id"
                DbType="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="dateCreate" DbType="DateTime" />
            <asp:Parameter Name="monthBegin" DbType="Int32" />
            <asp:Parameter Name="monthEnd" DbType="Int32" />
            <asp:Parameter Name="objectId" DbType="Int32" />
            <asp:Parameter Name="subContractId" DbType="Int32" />
        </UpdateParameters>
    </asp:ObjectDataSource>
    <!--unlinked objects data source-->
    <asp:ObjectDataSource ID="dsUnlinkedObject" runat="server" TypeName="PmSadis.WebFormsUi.Operator.SubContracts"
        SelectMethod="GetAllUnlinkedObjects" />
    <!--monthes data source-->
    <asp:ObjectDataSource ID="dsMonthes" runat="server" TypeName="PmSadis.WebFormsUi.Operator.SubContracts"
        SelectMethod="GetMonthes" />
    <asp:UpdatePanel ID="subContractsUpdatePanel" runat="server">
        <ContentTemplate>
            <dx:ASPxGridView ID="gvSubContracts" runat="server" DataSourceID="dsSubContracts" OnInit="gvSubContracts_Init"
                KeyFieldName="ContractId" OnRowUpdating="gvSubContracts_RowUpdating">
                <SettingsDetail ShowDetailButtons="true" ShowDetailRow="true" />
                <Columns>
                    <dx:GridViewDataColumn FieldName="ContractId" Visible="false" />
                    <dx:GridViewDataColumn FieldName="DateCreate" Visible="false" />
                    <dx:GridViewCommandColumn>
                        <NewButton Visible="true" />
                        <EditButton Visible="true" />
                        <DeleteButton Visible="true" />
                    </dx:GridViewCommandColumn>
                    <dx:GridViewDataTextColumn FieldName="Name" Caption="Наименование субконтракта" />
                    <dx:GridViewDataTextColumn FieldName="BlockName" Caption="Наименование блока" />
                </Columns>
                <Templates>
                    <DetailRow>
                        <h3>
                            Список объектов контракта
                            <%#Eval("Name")%>
                        </h3>
                        <dx:ASPxGridView ID="gvObjects" DataSourceID="dsObjects" KeyFieldName="ObjectInContractId"
                            runat="server" OnBeforePerformDataSelect="gvObjects_BeforePerformDataSelect" OnInit="gvObjects_Init" OnRowUpdating="gvObjects_RowUpdating" OnHtmlRowPrepared="gvObjects_HtmlRowPrepared">
                            <SettingsPager PageSize="10" />
                            <Columns>
                                <dx:GridViewDataColumn FieldName="ObjectInContractId" Visible="false" />
                                <dx:GridViewDataDateColumn FieldName="DateCreate" Visible="false" />
                                <dx:GridViewDataColumn FieldName="ObjectId" Visible="false" />
                                <dx:GridViewDataColumn FieldName="SubContractId" Visible="false" />
                                <dx:GridViewCommandColumn>
                                    <EditButton Visible="true" />
                                    <DeleteButton Visible="true" />
                                </dx:GridViewCommandColumn>
                                <dx:GridViewDataTextColumn FieldName="Code" Caption="Код">
                                    <EditFormSettings Visible="False" />
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn FieldName="Name" Caption="Наименование объекта содержания">
                                    <EditFormSettings Visible="False" />
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataComboBoxColumn FieldName="MonthBegin" Visible="false" Caption="Месяц начала обслуживания">
                                    <EditFormSettings Visible="True" />
                                    <PropertiesComboBox DataSourceID="dsMonthes" ValueField="MonthId" ValueType="System.Int32">
                                        <Columns>
                                            <dx:ListBoxColumn Caption="Год" FieldName="Year" />
                                            <dx:ListBoxColumn Caption="Месяц" FieldName="Name" />
                                        </Columns>
                                    </PropertiesComboBox>
                                </dx:GridViewDataComboBoxColumn>
                                <dx:GridViewDataComboBoxColumn FieldName="MonthEnd" Visible="false" Caption="Месяц окончания обслуживания">
                                    <EditFormSettings Visible="True" />
                                    <PropertiesComboBox DataSourceID="dsMonthes" ValueField="MonthId" ValueType="System.Int32">
                                        <Columns>
                                            <dx:ListBoxColumn Caption="Год" FieldName="Year" />
                                            <dx:ListBoxColumn Caption="Месяц" FieldName="Name" />
                                        </Columns>
                                    </PropertiesComboBox>
                                </dx:GridViewDataComboBoxColumn>
                            </Columns>
                        </dx:ASPxGridView>
                        <h4>
                            Привязать нераспределенные объекты</h4>
                        <asp:Table runat="server" Width="100%">
                            <asp:TableRow>
                                <asp:TableCell Width="200px">
                                    <dx:ASPxLabel runat="server" Text="Нераспределенные объекты:" />
                                </asp:TableCell>
                                <asp:TableCell>
                                    <dx:ASPxGridLookup ID="lucUnlinkedObjects" runat="server" DataSourceID="dsUnlinkedObject"
                                        KeyFieldName="ObjectInContractId" SelectionMode="Multiple" Width="100%" TextFormatString="{1}">
                                        <GridViewProperties>
                                            <Settings ShowFilterRow="true" ShowFilterRowMenu="true" ShowStatusBar="Visible" />
                                            <Templates>
                                                <StatusBar>
                                                    <div style="float: right;">
                                                        <dx:ASPxButton ID="btnLinkObjects" runat="server" Text="Привязать" Image-Url="~/Content/Images/Buttons/btnAddImage.gif"
                                                            OnClick="btnLinkObjects_Click" />
                                                    </div>
                                                </StatusBar>
                                            </Templates>
                                        </GridViewProperties>
                                        <Columns>
                                            <dx:GridViewDataColumn FieldName="ObjectInContractId" Visible="false" />
                                            <dx:GridViewCommandColumn ShowSelectCheckbox="true" Caption="Выбрать" />
                                            <dx:GridViewDataTextColumn FieldName="Code" Caption="Код" />
                                            <dx:GridViewDataTextColumn FieldName="Name" Caption="Наименование объекта содержания" />
                                        </Columns>
                                    </dx:ASPxGridLookup>
                                </asp:TableCell>
                            </asp:TableRow>
                        </asp:Table>
                    </DetailRow>
                </Templates>
            </dx:ASPxGridView>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
